package kt;

import ie.omk.smpp.Connection;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

/**
 * Example class to submit a message to a SMSC using synchronous communication.
 * This class simply binds to the server, submits a message, and then unbinds.
 * 
 * @see ie.omk.smpp.examples.ParseArgs ParseArgs for details on running this
 *      class.
 */
public class Ping2SMSCJob implements Job {
	//private Log logger = LogFactory.getLog(SendMTJob.class);
    private static final Logger logger = LogManager.getLogger(Ping2SMSCJob.class);
   
	public void execute(JobExecutionContext arg0) throws JobExecutionException {
		if (SMSGWThread.smscCnn.isBound()){
			try {
				SMSGWThread.smscCnn.enquireLink();
			} catch (Exception e) {
				logger.error("error when query the SMSC link", e);
			}
		} else {
			logger.error("the connection is not bindding, bind again");
			logger.info("Binding to the SMSC...");
			try {
				SMSGWThread.smscCnn.bind(Connection.TRANSCEIVER, GWConfig.parameters.systemID,
						GWConfig.parameters.password, GWConfig.parameters.systemType,
						GWConfig.parameters.sourceTON, GWConfig.parameters.sourceNPI,
						GWConfig.parameters.sourceAddress);
			} catch (Exception e) {
				logger.error("error when bind the SMSC link", e);
			}
		}
	}
}

